package org.example.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常
 */
@Slf4j
@RestControllerAdvice
public class GlobalException extends RuntimeException {

    /**
     * 处理全局异常
     * @param e 异常信息
     * @return
     */
    @ExceptionHandler(Exception.class)
    public AjaxResult customHandler(Exception e) {
        log.error("未捕捉的全局请求异常", e);
        return AjaxResult.error(500,e.getMessage());
    }

}